﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;

namespace 医院药库管理系统
{
    public partial class 管理员注册 : Form
    {
        public 管理员注册()
        {
            InitializeComponent();
        }

        private void bt_zc_Click(object sender, EventArgs e)
        {
            if (tb_name.Text == "" || tb_no.Text == "" || tb_password.Text == "")
            {
                MessageBox.Show("注册信息不能为空！");
            }
            SqlConnection sqlConnection = new SqlConnection();
            sqlConnection.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;                         
            SqlCommand sqlCommand = sqlConnection.CreateCommand();                                      
            sqlCommand.CommandText =
                "INSERT tb_Administrator (No,Name,Password) VALUES(@No,@Name,@Password);";               
            sqlCommand.Parameters.AddWithValue("@No", this.tb_no.Text.Trim());
            sqlCommand.Parameters.AddWithValue("@Name", this.tb_name.Text.Trim());
            sqlCommand.Parameters.AddWithValue("@Password", this.tb_password.Text.Trim());
            sqlCommand.Parameters["@Password"].SqlDbType = SqlDbType.VarChar;                           
            sqlConnection.Open();                                                                       
            int rowAffected = sqlCommand.ExecuteNonQuery();                                             
            sqlConnection.Close();                                                                      
            if (rowAffected == 1)                                                                       
            {
                MessageBox.Show("注册成功。");                                                          
            }
            else                                                                                        
            {
                MessageBox.Show("注册失败！");                                                        
            }
            管理员登录 f4 = new 管理员登录();
            f4.Show();
        }
    }
}
